package whu.cachhe.makeorder.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by CocoAdapter on 2018/4/7.
 */

public class DateTimeUtil {

    // 与后台约定的的 时间日期格式
    public static SimpleDateFormat baseFormat;

    static {
        baseFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    }

    public static Date parse(long time){
        try {
            return baseFormat.parse(baseFormat.format(new Date(time)));
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Date parse(String date){
        try {
            return baseFormat.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Date parse(Date date){
        try {
            return baseFormat.parse(baseFormat.format(date));
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String format(Date date){
        return baseFormat.format(date);
    }
}
